package com.zcx.qshop.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.zcx.qshop.R;
import com.zcx.qshop.adapter.ScreenAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/8/29 0029.
 */
public abstract class ScreenDialog extends QSDialog {

    public enum Screen {

        ONE("1", "价格低"),TWO("2", "价格高"),THREE("3", "数量");

        public String serchtype, name;

        Screen(String serchtype, String name){

            this.serchtype = serchtype;

            this.name = name;

        }

        public static List<Screen> getArray(){

            List<Screen> list = new ArrayList<>();

            list.add(ONE);

            list.add(TWO);

            list.add(THREE);

            return list;

        }

    }

    public ScreenDialog(Context context) {

        super(context);

        setCancelable(true);

        setContentView(R.layout.dialog_screen);

        ListView listView = (ListView) findViewById(R.id.screen_list_view);

        listView.setAdapter(new ScreenAdapter(context, Screen.getArray()));

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                ScreenDialog.this.onItemClick(Screen.getArray().get(position));

                dismiss();

            }

        });

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        getWindow().setGravity(Gravity.RIGHT | Gravity.TOP);

    }

    protected abstract void onItemClick(Screen itemScreen);

}
